import api from "../../../http/api";
export default {
	data() {
		return {
			tabs: [
			  { title: '代收' },
			  { title: '代付' }
			],
			activeTab: 0, // 当前激活的选项卡索引
			sliderStyle: {
			  width: '50%',
			  transform: 'translateX(0%)'
			},
			collectItems: [
			  { id: '1', range: '100-1000', rate: '', maxRate: 3,img:'/static/payImg/weixin.png' },
			  { id: '2', range: '1000-500000', rate: '', maxRate: 0 ,img:'/static/payImg/dingding.png' },
			  { id: '3', range: '100-1000000', rate: '', maxRate: 3 ,img:'/static/payImg/shuzirenmingbi.png' },
			  { id: '4', range: '100-10000', rate: '', maxRate: 0 ,img:'/static/payImg/yinghangkazhuangzhang.png' },
			  { id: '5', range: '100-100000', rate: '', maxRate: 0 ,img:'/static/payImg/weixin.png' },
			  { id: '6', range: '1000-50000', rate: '', maxRate: 0 ,img:'/static/payImg/yunshanfu.png' },
			],
			payItems: { id: '3', range: '1-50000', rate: '', maxRate: 0 },
			
			
			templates:1,//1当前模板2隐藏模板
			username:'',//下级账号
			collectDivide:[],//代收比例
			payDivide:{},//代付比例
			
		}
	},
	onLoad(option) {
		if(option && option.username){
			this.username = option.username
		}
		this.loadData(); // 首次加载数据
	},
	methods: {
		loadData(){
			let that = this;
			api.commissionRebateRatio({}).then(res=>{
				if(res.code==1){
					this.collectDivide = res.data.bank_rebate;
					this.collectDivide.forEach(item=>{
						item.rate = ''
					})
					this.payDivide = {
						payment_rebate:res.data.payment_rebate,
						bank_type_id:3,
						rate:''
					}
				}else{
					uni.showToast({ title: res.msg, icon: 'none' });
				}
			}).catch(err=>{
				
			})
		},
		/* 过滤器start */
		//收款渠道
		paytype(value){
			if(value==1){
				return '银行卡'
			}else if(value==2){
				return '微信'
			}else if(value==3){
				return '支付宝'
			}else if(value==4){
				return '云闪付'
			}else if(value==5){
				return '数字人民币'
			}else if(value==6){
				return '钉钉'
			}
		},
		//收款渠道图片
		payimg(value){
			if(value==1){
				return '/static/payImg/yinghangkazhuangzhang.png'
			}else if(value==2){
				return '/static/payImg/weixin.png'
			}else if(value==3){
				return '/static/payImg/zhifubao.png'
			}else if(value==4){
				return '/static/payImg/yunshanfu.png'
			}else if(value==5){
				return '/static/payImg/shuzirenmingbi.png'
			}else if(value==6){
				return '/static/payImg/dingding.png'
			}
		},
		//保存返佣比例
		save(){
			api.setRebate({
				username:this.username,
				bank_type_1:this.collectDivide[0].rate,
				bank_type_2:this.collectDivide[1].rate,
				bank_type_3:this.collectDivide[2].rate,
				bank_type_4:this.collectDivide[3].rate,
				bank_type_5:this.collectDivide[4].rate,
				bank_type_6:this.collectDivide[5].rate,
				payment_rebate:this.payDivide.rate
			}).then(res=>{
				if(res.code==1){
					uni.showToast({
						title: '保存成功',
						icon: 'success'
					});
					setTimeout(()=>{
						uni.navigateBack({delta:1})
					},1500)
					
				}else{
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			}).catch(err=>{
				
			})
		},
		/* 过滤器end */
		switchTab(index) {
		  this.activeTab = index;
		  
		  // 计算滑动指示器的位置
		  const translateX = index * 100;
		  this.sliderStyle = {
		    width: `${100 / this.tabs.length}%`,
		    transform: `translateX(${translateX}%)`,
		    transition: 'transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55)'
		  };
		}
	},
	mounted() {
	  // 初始化滑块位置
	  this.sliderStyle = {
	    width: `${100 / this.tabs.length}%`,
	    transform: `translateX(${this.activeTab * 100}%)`
	  };
	}
}